Copyright: WinG Pack version 1.0


Help Contents

This Help describes the WinG Pack v1.0.

What is the WinG Pack

How to install the WinG Pack

TWinGImage component

TWinG object

TDib256 object

Routines

Feedback

How to obtain the source code

Copyright


What is the WinG Pack

The WinG Pack includes:

- TWinGImage component.

- TDib256 and TWinG objects.

- Routines to deal with Dib Sprites and others.

I made this pack to provide the encapsulation of the WinG version 1.0 functions library and some additional tools so that anyone can ‘play’ with it easily. If you don’t already have WinG SDK it’s recommended that you download it from Microsoft ftp site and take a look at it’s documentation and samples.

Attention: this pack only works on Delphi 2.x (32 bit) and with the WinG32.DLL installed.

What is WinG?

WinG (pronounced "Win Gee") is an optimized library designed to enable these high-performance graphics techniques under Windows 3.x, Win32s, Windows NT 3.5, Windows 95, and future Windows releases. WinG allows the programmer to create a GDI compatible HBITMAP with a Device Independent Bitmap (DIB) as the drawing surface. Programmers can use GDI or their own code to draw onto this bitmap, then use WinG to transfer it quickly to the screen. WinG also provides halftoning APIs that use the standard Microsoft halftone palette to support simulation of true color on palette devices.


How to install the WinG Pack

To Install the Component

1. Choose the Install option from the component menu.

2. Press the Add Button

3. Select WinGImag.DCU changing the path if necessary.

4. Press OK Twice.

5. The components are now installed onto the system tab of the component selector.

To Install the WinG32.DLL

1. 	If you have the WinG SDK install it or else

2. 	Unzip the file WING32.ZIP in this pack to your Window’s System directory.

To Install the WinG Pack Help

(These instructions assume that your copy of Delphi is installed in C:\DELPHI

 If not adjust the paths accordingly)

1. Copy WINGPACK.KWF to C:\DELPHI\HELP.

2. Copy WINGPACK.HLP to C:\DELPHI\BIN.

3. Run HELPINST from your delphi folder.

4. Use.FILE|OPEN to open C:\DELPHI\BIN\DELPHI.HDX.

5. Use KEYWORDS|ADD KEYWORD FILE to add C:\DELPHI\HELP\WINGPACK.KWF.

6. Use FILE|SAVE to Compile and save the new HDX file.

7. Online help is now installed.


TWinGImage component

The TWinGImage is a descendent of TGraphicControl. Use it to display a graphical image on a form using the WinG library. You can set a default image by setting the FileName property. If you want the wingimage control to resize to fit the current image, set the AutoSize property to True. If you want to see only a region of an image use the View property.

The TWinGImage component automatically makes an identity palette with 236 colors (it excludes the 20 system colors). You should not use the first and last 10 colors because they belong to the system and you also shouldn't put more than one of this components in a form because there aren't colors for everybody, if running with a 256 color display driver. Naturally when you load an image only the 10-245 color indexes are initialized so the other colors will not correspond to the true image colors. To avoid this just prepare your images so that they don't use such color indexes. To maximize your performance it's recommended that you consult the WinG Documentation.

Properties:

AutoSize

Canvas

FileName

Palette

View

WinG

Methods:

LoadFromFile

SetPalette


Feedback

I would appreciate some feedback, especially bugs or improvements that you think that I should make. In the event of you finding a bug, see if you can reproduce it in a simple piece of code and email me that code. As soon as the bug is fixed you will be sent an intermediate version with the bug fix.

Email: si14525@ci.uminho.pt

Mail:	Carlos Barbosa

Passos - Fajoes

3700 S. J. Madeira

Portugal


How to obtain the Source Code

The Source code to this WinG Pack are available directly from the author at a cost of US $30.00. For this you will receive the source to all future versions of WinG Pack (including intermediate bug fix releases) due to the price the source can only be distributed via e-mail.

The author can be contacted at

Email: si14525@ci.uminho.pt

Mail:	Carlos Barbosa

Passos - Fajoes

3700 S. J. Madeira

Portugal


Copyright

There are no restrictions placed on the use of this WinG Pack in compiled DCU format or linked into an EXE or DLL..

The source code is licensed to the purchaser to use in any of his/her development but remains copyrighted to Carlos Barbosa and may not be distributed in to any other parties without the written permission of Carlos Barbosa.


AutoSize property
AutoSize

Applies to

TWinGImage

Declaration

property AutoSize: Boolean;

Description

When the AutoSize property is True, the image control resizes to accommodate the image it contains. When AutoSize is False, the image control remains the same size, regardless of the size of the image. If the image control is smaller than the image, the picture will be croped.


Canvas property
Canvas

Applies to

TWinGImage

Declaration

property Canvas: Canvas;

Description

Read and run-time only. The Canvas property gives you access to the drawing surface.


FileName property
FileName

Applies to

TWinGImage

Declaration

property FileName: TFileName;

Description

This property has the name of the file to be loaded. The file must be in Bitmap File Format, uncompressed or compressed, 8 bits per pixel. Not all bitmap formats are supported. The image will be loaded whenever you set this property or resize the component.


Palette property
Palette

Applies to

TWinGImage

Declaration

property Palette: HPalette;

Description

Read and run-time only. This property returns the handle to the 256 color Logical Palette. To set the palette use the SetPalette method.


View property
View

Applies to

TWinGImage

Declaration

property View: TView;

Description

With view you can set the rectangle of the image that you see.

TView properties

 Mode - Can be All or Portion. If you select All the view rectangle will be ignored, and all the image will be shown.

 Left, Height, Top, Width - Defines the view rectangle of the image.


WinG property
WinG

Applies to

TWinGImage

Declaration

property WinG: TWinG;

Description

This property contains the image of the TWinGImage component.


LoadFromFile method
LoadFromFile

Applies to

TWinGImage

Declaration

procedure LoadFromFile;

Description

The LoadFromFile method reads the file specified in FileName property and loads the data into the TWinGImage component. Use this to refresh a corrupted image.


SetPalette method
SetPalette

Applies to

TWinGImage

Declaration

procedure SetPalette( Colors: PRGBQUAD; wStartIndex, nEntries: Word );

Description

With this method you set the palette color table from index wStartIndex to wStartIndex+nEntries-1 with the values in the Colors RGBQUAD array. Only the indexes 10-245 can be set, the others are system colors and can’t be changed.


TWinG object

The TWinG object is a descendent of TPersistent and it basically offers the encapsulation of the WinG version 1.0 library. This object creates automatically the WinG Bitmap and WinG DC accordingly to the given dimensions. For a question of simplification the WinG Dib orientation is always top-down, independent of the value return by WinGRecommendDibFormat.

You use Create method to initialize the object with the dimensions given by parameter. To change the dimensions of the image just set the Width and Height properties.

Properties:

Bitmap

ColorTable

Handle

Height

Pixels

Width

WidthBytes

Methods:

BitBlt

Create

StretchBlt

Events:

OnChange

Exceptions:

EWinGError


Bitmap property
Bitmap

Applies to

TWinG

Declaration

property Bitmap:HBITMAP;

Description

Read and run-time only. Returns the value of the WinG bitmap handle, 0 if none is created.


ColorTable property
ColorTable

Applies to

TWinG

Declaration

property ColorTable: PRGBQUAD;

Description

Read and run-time only. This property returns the pointer to the 256 color table where you should only read the values, not write.


Handle property
Handle

Applies to

TWinG

Declaration

property Handle: HDC;

Description

Read and run-time only. Returns the WinG Display Context handle, or 0 if none is created.


Height property
Height

Applies to

TWinG

Declaration

property Height: Word;

Description

You can change the Height of the WinG image by setting this property. When you do it, an On Change event will occur.


Pixels property
Pixels

Applies to

TWinG

Declaration

property Pixels: Pointer;

Description

Read and run-time only. Gives you the pointer to the memory location where the image pixels are defined. Each byte has the color value from 0 to 255 of each pixel. You can directly access the memory to change the image, using your own routines.


Width property
Width

Applies to

TWinG

Declaration

property Width: Word;

Description

You can change the Width of the WinG image by setting this property. When you do it, an On Change event will occur.


WidthBytes property
WidthBytes

Applies to

TWinG

Declaration

property WidthBytes: Word;

Description

Read and run-time only. Returns the width of the image in bytes, which corresponds to the image pixels width aligned to 4 bytes.


BitBlt method
BitBlt

Applies to

TWinG

Declaration

function BitBlt( hdcDst: HDC; nXOriginDst, nYOriginDst, nWidthDst, nHeightDst: Integer; nXOriginSrc, nYOriginSrc: Integer ): Boolean;

Description

The BitBlt method copies a bitmap from the WinG device context to a destination device context. See the WinGBitBlt routine.


Create method
Create

Applies to

TWinG

Declaration

constructor Create( wWidth, wHeight: Word );

Description

The Create method constructs a new TWinG object with an image dimensions of (wWidth, wHeight).


StretchBlt method
StretchBlt

Applies to

TWinG

Declaration

function StretchBlt( hdcDst: HDC; nXOriginDst, nYOriginDst, nWidthDst, nHeightDst: Integer; nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc: Integer): Boolean;

Description

The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap if necessary to fit the dimensions of the destination rectangle. See the WinGStretchBlt routine.


OnChange event
OnChange

Applies to

TWinG

Declaration

property OnChange: TNotifyEvent;

Description

The OnChange event occurs when either the Width or Height properties change.


EWinGError exception
EWinGError

Applies to

TWinG

Declaration

EWinGError = class(Exception);

Description

This exception is raised if it fails to call WinGRecommendFormat routine, create a WinG DC or WinG bitmap.


TDib256 object

The TDib256 is a descendent of TObject. It provides a way of loading/saving or even creating bitmap files, with 8 bits per pixel only. It supports loading of compressed bitmaps but not saving them.

Some bitmap file formats are not supported, so if you have any problems reading a bitmap file just try to load and save it in a application like Paint Shop Pro or Corel Photo-Paint.

To load an image use LoadFromFile and SaveToFile to save the current image.

Properties:

ColorTable

Dib

Height

ImageSize

Pixels

Width

WidthBytes

Methods:

FlipImage

LoadFromFile

SaveToFile


ColorTable property
ColorTable

Applies to

TDib256

Declaration

TRGBQUAD256 = array [0..255] of TRGBQUAD;

PRGBQUAD256 = ^TRGBQUAD256;

property ColorTable: PRGBQUAD256;

Description

This property returns the pointer to the 256 color table, where you can read/write the palette entries.


Dib property
Dib

Applies to

TDib256

Declaration

TRGBQUAD256 = array [0..255] of TRGBQUAD;

TDIB256INFO = record

bmiHeader: TBITMAPINFOHEADER;

bmiColors: TRGBQUAD256;

end;

PDIB256INFO = ^TDIB256INFO;

property Dib: PDIB256INFO;

Description

Gives you the pointer to the whole struture of the DIB.


ImageSize property
ImageSize

Applies to

TDib256

Declaration

property ImageSize: Longint;

Description

Use this property to change the Height of the image.


Height property
Height

Applies to

TDib256

Declaration

property Height: Word;

Description

Use this property to change the Height of the image. When you resize the image, all its contents will be deleted.


Pixels property
Pixels

Applies to

TDib256

Declaration

property Pixels: Pointer;

Description

Gives you the pointer to the memory location where the image pixels are defined. Each byte has the color value from 0 to 255 of each pixel.


Width property
Width

Applies to

TDib256

Declaration

property Width: Word;

Description

Use this property to change the Width of the image. When you resize the image, all its contents will be deleted.


WidthBytes property
WidthBytes

Applies to

TDib256

Declaration

property WidthBytes: Word;

Description

Returns the width of the image in bytes, which corresponds to the image pixels width aligned to 4 bytes.


FlipImage method
FlipImage

Applies to

TDib256

Declaration

procedure FlipImage;

Description

The FlipImage method turns the image upside-down, this method is used internally by LoadFromFile and SaveToFile methods, because bitmap images are stored upside-down.


LoadFromFile method
LoadFromFile

Applies to

TDib256

Declaration

procedure LoadFromFile( const FileName: string );

Description

The LoadFromFile method reads the FileName file and resizes the image. If any error occurs concerning the file format an EInvalidGraphic exception is raised.


SaveToFile method
SaveToFile

Applies to

TDib256

Declaration

procedure SaveToFile( const FileName: string );

Description

This method saves the current image to a bitmap file format, uncompressed.


Routines

ClearSystemPalette

CompressBitmap

CopyDIBBits

DecompressBitmap

TransCopyDIBBits

WinGBitBlt

WinGCreateBitmap

WinGCreateDC

WinGCreateHalftoneBrush

WinGCreateHalftonePalette

WinGGetDIBColorTable

WinGGetDIBPointer

WinGRecommendDIBFormat

WinGSetDIBColorTable

WinGStretchBlt


ClearSystemPalette routine
ClearSystemPalette

Unit

WinGImag

Declaration

procedure ClearSystemPalette;

Description

This procedure realizes a completely black palette, which is a good idea before you realize an identity palette for the first time. This will ensure that palette-managed applications executed before your application will not affect the identity mapping of your carefully constructed palette.


CompressBitmap routine
CompressBitmap

Unit

Dib256

Declaration

function CompressBitmap( pSource, pDest: Pointer; NBytes: Longint ): Longint;

Description

The CompressBitmap function compresses a bitmap using the BI_RLE8 method. It’s not fully optimized, but it works (at least it worked as far as I tested). You must point the uncompressed data with pSource and the destination with pDest, and also the number of bytes to compress, NBytes. The function returns the total of bytes occupied in the compressed format. Be carefull to reserve enough destination memory before calling the function, and after returning you can realocate only to the necessary memory.


CopyDIBBits routine
CopyDIBBits

Unit

Dib256

Declaration

procedure CopyDIBBits( pDest, pSource: Pointer; dwWidth, dwHeight: Longint; dwScanD, dwScanS: Longint );

Description

This routine has the purpose of copying block of images without transparency, from pSource to pDest. You specify the dimensions of the block with dwWidth and dwHeight, the width in bytes of the destination and source images with dwScanD and dwScanS, respectively. See also TransCopyDIBBits.


DecompressBitmap routine
DecompressBitmap

Unit

Dib256

Declaration

procedure DecompressBitmap( pDest, pSource: Pointer; wWidth: Word );

Description

This procedure let’s you decompress a bitmap file using the method BI_RLE8 only. The pSource points to the compressed data and pDest to the resulting uncompressed data. You must specify the width in bytes of the bitmap with wWidth.


TransCopyDIBBits routine
TransCopyDIBBits

Unit

Dib256

Declaration

procedure TranscopyDIBBits( pDest, pSource: Pointer; dwWidth, dwHeight: Longint; dwScanD, dwScanS: Longint; bTranClr: Byte );

Description

This routine has the purpose of copying block of images with transparency, from pSource to pDest. You specify the dimensions of the block with dwWidth and dwHeight, the width in bytes of the destination and source images with dwScanD and dwScanS, respectively. bTranClr defines the transparent color. See also CopyDIBBits.


WinGBitBlt routine
WinGBitBlt

Unit

WinG

Declaration

function WinGBitBlt( hdcDst: hDC; nXOriginDst, nYOriginDst, nWidthDst, nHeightDst: Integer; hdcSrc:hDC; nXOriginSrc, nYOriginSrc: Integer ): Boolean;

Description

Copies an area from a specified device context to a destination device context. WinGBitBlt is optimized to copy WinGDCs to display Dcs. It does not operate on any other types of Device Contexts. See WinG Programmer’s Reference for additional information.


WinGCreateBitmap routine
WinGCreateBitmap

Unit

WinG

Declaration

function WinGCreateBitmap( WinGDC: hDC; pHeader:pBitmapInfo; ppBits:pointer): HBitmap;

Description

Creates a WinGBitmap for the given WinGDC using the specified header information. See WinG Programmer’s Reference for additional information.


WinGCreateDC routine
WinGCreateDC

Unit

WinG

Declaration

function WinGCreateDC: hDC;

Description

Creates a WinG device context with the stock 1x1 monochrome bitmap selected. See WinG Programmer’s Reference for additional information.


WinGCreateHalftoneBrush routine
WinGCreateHalftoneBrush

Unit

WinG

Declaration

function WinGCreateHalftoneBrush( context: hDC; crColor:tColorRef; ditherType:tWinGDither ): HBrush;

Description

Creates a dithered pattern brush based on the WinG halftone palette. See WinG Programmer’s Reference for additional information.


WinGCreateHalftonePalette routine
WinGCreateHalftonePalette

Unit

WinG

Declaration

function WinGCreateHalftonePalette: HPalette;

Description

Creates an 8-bit palette used for halftoning images. See WinG Programmer’s Reference for additional information.


WinGGetDIBColorTable routine
WinGGetDIBColorTable

Unit

WinG

Declaration

function WinGGetDIBColorTable( WinGDC: HDC; StartIndex, NumberOfEntries: Word; pColors: Pointer): Word;

Description

Returns the color table of the WinGBitmap currently selected into a WinGDC. See WinG Programmer’s Reference for additional information.


WinGGetDIBPointer routine
WinGGetDIBPointer

Unit

WinG

Declaration

function WinGGetDIBPointer( WinGBitmap: HBitmap; pHeader: pBitmapInfo): Pointer;

Description

Retrieves information about a WinGBitmap and returns a pointer to its surface. See WinG Programmer’s Reference for additional information.


WinGRecommendDIBFormat routine
WinGRecommendDIBFormat

Unit

WinG

Declaration

function WinGRecommendDIBFormat( pFormat: PBitmapInfo ): Boolean;

Description

Fills in the entries of a BITMAPINFO structure with values that will give maximum performance for memory-to-screen 1:1 identity blts using WinG. See WinG Programmer’s Reference for additional information.


WinGSetDIBColorTable routine
WinGSetDIBColorTable

Unit

WinG

Declaration

function WinGSetDIBColorTable( WinGDC: HDC; StartIndex, NumberOfEntries: Word; pColors: Pointer): Word;

Description

Modifies the color table of the currently selected WinGBitmap in a WinGDC. See WinG Programmer’s Reference for additional information.


WinGStretchBlt routine
WinGStretchBlt

Unit

WinG

Declaration

function WinGStretchBlt( hdcDst: HDC; nXOriginDst, nYOriginDst, nWidthDst, nHeightDst: Integer; hdcSrc: HDC; nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc: Integer): Boolean;

Description

Copies an area from the source specified device context to an area of the destination device context, resizing if necessary to fill the destination rectangle. WinGStretchBlt is optimized to copy WinGDCs to display DCs. It does not operate on any other types of Device Contexts. See WinG Programmer’s Reference for additional information.